# Harris 1969 American Foreign Policy Survey, study no. 1970
## packages 
library("Hmisc")
library("dplyr")


## set working directory to replication repository

## download data
survey <- sasxport.get("Harris_Data/Harris 1969 American Foreign Policy Survey, study no. 1970/harris_s1970_sas.export")

## pid
survey$pid <- c(1:nrow(survey))
table(survey$pid)

## study number
survey$study <- as.character(1970)
table(survey$study)

## year
survey$year <- 1969
table(survey$year)

## geographpic data
survey$urban <- NA
table(survey$urban)

## region 
survey$region <- NA

## respondent name
table(survey$f1)
survey$hh <- as.character(survey$f1)

## inequality increasing
table(survey$q17.a)
survey$inequality <- as.character(survey$q17.a)
table(survey$inequality)

## inequality variable version
survey$inequality.variable <- 1
table(survey$inequality.variable)

## union 
summary(survey$f3.1) ## are you a union member
summary(survey$f3.2) ## is any member of family a union member

survey$union.self <- as.character(survey$f3.1)
survey$union.other <- as.character(survey$f3.2)
table(survey$union.self)
table(survey$union.other)

## Are you employed? what kind of employment?
survey$employed <- as.character(survey$f2a)
table(survey$employed)

## empl self
survey$employed.self <- NA

## Occupation
summary(survey$f2b)
survey$occupation <- as.character(survey$f2b)
table(survey$occupation)

## occ self
survey$occupation.self <- NA
## household size
survey$hhsize <- NA
table(survey$hhsize)

## Education
summary(survey$f6)
survey$educ <- as.character(survey$f6)
table(survey$educ)

## Income
summary(survey$f9)
survey$income <- as.character(survey$f9)
summary(survey$income)
table(survey$income)

## Age 
survey$age <- ifelse(is.na(survey$f8.1), 
                     as.character(survey$f8.2), 
                     as.character(survey$f8.1))
table(survey$age)
summary(survey$age)

## race
summary(survey$F10)
survey$race <- as.character(survey$f10)
table(survey$race)

## politics 
survey$party <- NA

## ideology
survey$ideology <- NA

## gender
summary(survey$s1)
survey$gender <- as.character(recode(survey$s1,
                                      `MALE` = "Male",
                                      `FEMALE` = "Female"))
table(survey$gender)

## religion
summary(survey$f7)
survey$religion <- as.character(survey$f7)
table(survey$religion)

#factuals
survey$factual1 <- NA
survey$factual2 <- NA
survey$factual3 <- NA

## alienation index
survey$dontcare <- as.character(survey$q17.b)
survey$dontcount <- as.character(survey$q17.c)
survey$leftout <- as.character(survey$q17.h)

## question_placement
survey$question_place <- "no party question"

# subset
survey_1970 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
                         "inequality", "inequality.variable", "union.self", "union.other",
                         "employed", "employed.self", "occupation", "occupation.self", "hhsize", "educ", "income", 
                         "age", "race", "party", "ideology", "gender", "religion",
                         "factual1", "factual2", "factual3", "dontcare", "dontcount", "leftout",
                         "question_place")]


## save dataset 
#saveRDS(survey_1970, file = "Harris_Data/survey_1970.rds")



